package com.zb.controller;

import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.zb.exception.SMSException;
import com.zb.result.Result;
import com.zb.service.VerificSMSService;
import com.zb.utils.VerificUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @Author WEN
 * @Date 2023/7/10 0010
 **/
@Api(tags = "短信类接口")
@RestController
@RequestMapping("/sms")
public class SMSController {

    @ApiOperation("登录类验证码")
    @GetMapping("/loginCode")
    public Result loginCode(@ApiParam(value = "手机号", required = true) String phone) throws SMSException {
        Assert.isTrue(VerificUtil.phoneVerific(phone), "请输入正确的手机号格式！", phone);
        VerificSMSService.sendLoginVerificCode(phone);
        return Result.success("验证码发送成功！");
    }

    @ApiOperation("更改类验证码")
    @GetMapping("/updateCode")
    public Result updateCode(@ApiParam(value = "手机号", required = true) String phone) throws SMSException {
        Assert.isTrue(VerificUtil.phoneVerific(phone), "请输入正确的手机号格式！", phone);
        VerificSMSService.sendUpdateVerificCode(phone);
        return Result.success("验证码发送成功！");
    }
}
